<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="js/layui/css/layui.css"  media="all">
  <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
  <script src="js/layer/layer.js" type="text/javascript" charset="utf-8"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
 
<table class="layui-hide" id="test" lay-filter="test"></table>
 
<!-- <script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
  </div>
</script> -->
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="sysDaepart">更改部门</a>
  <a class="layui-btn layui-btn-xs" lay-event="update">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
              
          
<script src="js/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 --> 
 
<script>
layui.use('table', function(){
  var table = layui.table;
  
  table.render({
    elem: '#test'
    ,url:'http://127.0.0.1:8080//clazz/clazzfindAll'
  
    ,defaultToolbar: [ 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
      title: '提示'
      ,layEvent: 'LAYTABLE_TIPS'
      ,icon: 'layui-icon-tips'
    }]
    ,title: '用户数据表'
    ,cols: [[
      
      {field:'clazzid', title:'ID', width:180, fixed: 'left', unresize: true, sort: true,hide:true}
      ,{field:'clazzno', title:'班级编号', width:220}
      ,{field:'classname', title:'班级名称', width:220, edit: 'text'}
	  ,{field:'departmentid', title:'所属部门', width:220}
	
     
      
   
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
    ]]
    ,page: {
			  layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,limit:10 //一页显示多少条
                ,limits:[5,10,15]//每页条数的选择项
                ,groups: 2 //只显示 2 个连续页码
                ,first: "首页" //不显示首页
                ,last: "尾页" //不显示尾页

		 }
  });
  
  //头工具栏事件
  table.on('toolbar(test)', function(obj){
    var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){
      case 'getCheckData':
        var data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      break;
      case 'getCheckLength':
        var data = checkStatus.data;
        layer.msg('选中了：'+ data.length + ' 个');
      break;
      case 'isAll':
        layer.msg(checkStatus.isAll ? '全选': '未全选');
      break;
      
      //自定义头工具栏右侧图标 - 提示
      case 'LAYTABLE_TIPS':
        layer.alert('这是工具栏右侧自定义的一个图标按钮');
      break;
    };
  });
  
  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    //console.log(obj)
    if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        obj.del();
        layer.close(index);
		
		
		$.ajax({ 
			
                type:"get",
                url:"http://127.0.0.1:8080//clazz/delete",
                 dataType: 'json',
               contentType: "application/json;charset=utf-8",

              data:{"clazzid":obj.data.clazzid},
			 success:function(msg){
				 
				 layer.msg(msg.data, {time:1000, icon:6, shift:6}, function(){});
			 }
		})
      });
    } else if(obj.event === 'edit'){
      layer.prompt({
        formType: 2
        ,value: data.email
      }, function(value, index){
        obj.update({
          email: value
        });
        layer.close(index);
      });
    }else if(obj.event==="update"){
		  var clazzid=obj.data.clazzid;
		  var clazzno=obj.data.clazzno;
		  var classname=obj.data.classname;
		  var departmentid=obj.data.departmentid;
		  var isDelete=obj.data.isDelete;
		  var data={
			  "clazzid":clazzid,
			  "clazzno":clazzno,
			  "classname":classname,
			  "departmentid":departmentid,
			  "isDelete":isDelete,
		  }
		 $.ajax({
			 type:"post",
			    url:"http://127.0.0.1:8080//clazz/update",
			    dataType: 'json',
			   contentType: "application/json;charset=utf-8",
			    
			 data: JSON.stringify(data),
			  success:function(msg){
				 
				layer.msg(msg.data, {time:1000, icon:6, shift:6}, function(){});
			  },
			  error:function(){
				  layer.msg("更新失败哟", {time:1000, icon:5, shift:6}, function(){});
			  }
		 })
	}else if(obj.event==="sysDaepart"){
			layer.open({
		  type: 2,
		  area: ['700px', '450px'],
		  fixed: false, //不固定
		  maxmin: true,
		  content: 'sysDpart.html?userid='+obj.data.clazzid
		});
	}
  });
});
</script>
  <button class="layui-btn layui-btn-sm" lay-event="table" id="addStu">添加</button>
  
</body>
<script type="text/javascript">
	$("#addStu").click(function(){
		layer.open({
		  type: 2,
		  area: ['700px', '450px'],
		  fixed: false, //不固定
		  maxmin: true,
		  content: 'SysaddClazz.html'
		});
	})
</script>
</html>